<template>
  <div class="login-container">
    <!-- 导航栏 -->
    <van-nav-bar class="page-nav-bar" title="登录" />
    <!-- 导航栏 -->

    <!-- 登陆表单 -->
<van-form @submit="onSubmit">
  <van-cell-group>
            <van-field
            v-model="user.mobile"
             required
            clearable
            name="用户名"
            placeholder="请输入手机号"
            >
             <i slot="left-icon" class="toutiao toutiao-shouji"></i>
            </van-field>
            <van-field
            v-model="user.code"
            type="number"
            name="密码"
            placeholder="请输入验证码"
            required
            >
            <i slot="left-icon" class="toutiao toutiao-yanzhengma"></i>
        <template #button>
          <van-button class="send-sms-btn" round size="small" type="default">发送验证码</van-button>
        </template>
            </van-field>
    </van-cell-group>
          <div class="login-btn-wrap">
        <van-button class="login-btn" block type="info" native-type="submit">
          登录
        </van-button>
      </div>
</van-form>
<!-- /登陆表单 -->
  </div>
  
</template>

<script>
import {login ,getUserInfo} from "@/api/user"
export default {
  name: 'LoginIndex',
  components: {},
  props: {},
  data () {
    return {
       user:{
        mobile: '13800000001',
        code: '246810'
      }
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {},
  methods: {
    async onSubmit () {
      // 开始转圈圈
     this.$toast.loading({
    duration: 0, // 持续时间，0表示持续展示不停止
    forbidClick: true, // 是否禁止背景点击
    message: '登录中...' // 提示消息
  })

     try {
        const res = await login(this.user);
        // console.log(res);
        // console.log("登录成功", res);
        this.$router.push("/my");
        this.$toast.success("成功登录");
        this.$store.commit("setUser", res.data.data);

    
       
      } catch (err) {
        console.log(err);
        console.log("登录失败", err);
        this.$toast.fail("登录失败，手机号或验证码错误");
      }
    }
  }
}
</script>
<style scoped lang="less">

</style>
